/*

package com.ruoyi.runner;

import com.ruoyi.order.domain.MesDetectNode;
import com.ruoyi.order.service.IConfigService;
import com.ruoyi.order.service.IMesDetectNodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

@Order(3)
@Component
@Slf4j
public class ScanMultiThreadRunner implements ApplicationRunner {

    @Autowired
    private ScanPLCService scanPLCService;

    @Autowired
    private IMesDetectNodeService detectNodeService;
    @Autowired
    private IConfigService configService;


*/
/**
     * 启动项目时启动多线程,每个线程循环执行一个节点
     * @param args
     * @throws Exception
     *//*


    @Override
    public void run(ApplicationArguments args) throws Exception {
        //操作指引扫描标志
        String operateFlag = configService.selectConfigByKey("plc_operate_flag");
        //生产数据扫描标志
        String productDataFlag = configService.selectConfigByKey("plc_product_data_flag");
        //操作指引定点扫描站号
        String scanNode = configService.selectConfigByKey("plc_product_data_node");
        //产线号
        String lineNumber = configService.selectConfigByKey("line_number");
        MesDetectNode param = new MesDetectNode();
        param.setSubsysCode(lineNumber);
        List<MesDetectNode> detectNodeList = detectNodeService.selectMesDetectNodeList(param);
        for (MesDetectNode mesDetectNode : detectNodeList) {
            //循环实现扫描PLC 生产数据
            if (productDataFlag.equals("true")) {
                new Thread(() -> {
                    while (true) {
                        log.info("执行 scanPLCService.handleNode,生产数据处理");
                        scanPLCService.handleNode(mesDetectNode, detectNodeList.size());
                        try {
                            Thread.sleep(400);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }
        MesDetectNode operationNode = new MesDetectNode();
        for (MesDetectNode mesDetectNode : detectNodeList){
            if (mesDetectNode.getNodeCode().equals(scanNode)){
                operationNode = mesDetectNode;
            }
        }
        //循环实现扫描PLC 操作数据
        if (operateFlag.equals("true")) {
            while (true) {
                log.info("执行 scanPLCService.operateGuide,操作指引数据处理");
                scanPLCService.operateGuide("1", operationNode, scanNode);
                try {
                    Thread.sleep(600);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

*/
